<?php
namespace app\common\lib\model_operate;

/**
 * 追踪类
 */
class Trace
{
    private $function; //调用方法
    private $class; //调用类
    private $controller; //控制器
    private $app; //应用

    /**
     * 构造方法
     */
    public function __construct(array $trace, $num = 1)
    {
        if (isset($trace[$num])) {
            if (isset($trace[$num]['function'])) {
                $this->function = $trace[$num]['function'];
            }
            if (isset($trace[$num]['class'])) {
                $this->class      = $trace[$num]['class'];
                $this->controller = substr($this->class, strrpos($this->class, '\\') + 1);
                $str              = str_replace('\\', '', $this->class);
                $this->app        = preg_replace('/plugins|controller[\S]{0,}/i', '', $str);
            }
        }
    }

    //获取器
    public function getFunc()
    {
        return $this->function;
    }
    public function getClass()
    {
        return $this->class;
    }
    public function getApp()
    {
        return $this->app;
    }
    public function getController()
    {
        return $this->controller;
    }
}
